import {Config} from '../../utils/conf.js';
import {httpReq} from '../../utils/http.js';

class ques
{
  //获取所有分类
  getcate(that){
    let obj = {};
    obj.url = Config.getcate;
    httpReq(obj).then(res=>{
      let arrs = [{id:0,cate:'请选择问题分类'}];
      res.data.data.forEach(element => {
        arrs.push({id:element.id,cate:element.cate});
      });
      that.setData({
        arr: arrs
      })
    })
  }
  
  //提交问题
  saveq(that,cid,title,content){
    let obj = {};
    obj.url = Config.saveque;
    obj.data = {cid,title,content,uid:wx.getStorageSync("uid")},
    obj.method = 'post';
    httpReq(obj).then(res=>{
      let qid = res.data.data.id;
      let que = res.data.data.title;
      let con = res.data.data.content;
      that.setData({
        ccc:'',
        ttt:''
      })
      wx.showToast({
        title: '提交成功',
        icon :'success'
      })
      wx.navigateTo({
        url: '/pages/info/info?qid=' + qid + '&que='+ que +'&con='+ con +'&aid=0&ans=0'
      })
    })
  }
}

export default ques;